package com.easywan.web.controller.system;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.easywan.core.JSPModelAndView;
import com.easywan.core.SystemDesign;
import com.easywan.service.ArticleService;
import com.easywan.service.EasywanSystemIndexService;
import com.easywan.service.SpotsService;
import com.easywan.vo.EasywanSystemIndex;
import com.easywan.vo.base.BaseModel;

@Controller
public class IndexController {
	@Autowired
	private ArticleService articleService;
	@Autowired
	private EasywanSystemIndexService systemIndexService;
	@Autowired
	private SpotsService spotsService;
	@RequestMapping("index")
	public ModelAndView index(HttpServletResponse res,HttpServletRequest req,HttpSession session,ModelMap modelMap){
		ModelAndView view = new JSPModelAndView("system/index");
		/*List<Article> articles =  articleService.selectLast(4);
		view.addObject("articleList",articles);*/
		//BANNER
		List<EasywanSystemIndex> systemIndexs = systemIndexService.selectBanner();
		view.addObject("banner", systemIndexs);
		List<EasywanSystemIndex> systemIndexTj = systemIndexService.selectTj();
		view.addObject("tj1", systemIndexTj);
		List<EasywanSystemIndex> systemIndexTj2 = systemIndexService.selectTj2();
		view.addObject("tj2", systemIndexTj2);
		List<EasywanSystemIndex> systemIndexMk1 = systemIndexService.selectByName(SystemDesign.INDEX_MK1.getValue());
		view.addObject("mk1", systemIndexMk1);
		//mk2
		List<BaseModel> systemIndexMk2 = systemIndexService.selectByNameMk(SystemDesign.INDEX_MK2.getValue());
		view.addObject("mk2", systemIndexMk2);
		/*List<Spots> systemIndexMk2 = spotsService.list(
				(Spots)(new Spots().
						setPage(new Pages().
						setPageSize(8)).
						setOrder("order by looks desc")));
		view.addObject("mk2", systemIndexMk2);*/
		//模块排行2
		List<EasywanSystemIndex> systemIndexMkPh2 = systemIndexService.selectByName(SystemDesign.INDEX_PH2.getValue());
		view.addObject("mkph2", systemIndexMkPh2);
		
		
		List<BaseModel> systemIndexMk3 = systemIndexService.selectByNameMk(SystemDesign.INDEX_MK3.getValue());
		view.addObject("mk3", systemIndexMk3);
		//模块排行2
		List<EasywanSystemIndex> systemIndexMkPh3 = systemIndexService.selectByName(SystemDesign.INDEX_PH3.getValue());
		view.addObject("mkph3", systemIndexMkPh3);
		
		return view;
	}
	@RequestMapping("error")
	public ModelAndView error404(){
		return new JSPModelAndView("system/404");
	}
	@RequestMapping("500")
	public ModelAndView error500(){
		return new JSPModelAndView("system/404");
	}
}
